# 3. 无重复字符的最长子串
def lengthOfLongestSubstring(s: str) -> int:
    start_index = 0
    end_index = 0
    max_length = 0
    s_len = len(s)
    while end_index < s_len:
        # 当前字符
        end_char = s[end_index]
        # 当前的字符串
        s_slice = s[start_index:end_index]
        # 判断当前字符与窗口的字符是否有重复
        if end_char in s_slice:
            first_index = s_slice.index(end_char)
            start_index = start_index + first_index + 1

        # 往后滑动一个位置
        end_index += 1

        # 判断最大长度
        max_length = max(max_length, end_index - start_index)
    return max_length


result = lengthOfLongestSubstring('abcabcbb')
print(f"result:{result}")

result = lengthOfLongestSubstring('bbbbb')
print(f"result:{result}")

result = lengthOfLongestSubstring('pwwkew')
print(f"result:{result}")

result = lengthOfLongestSubstring('')
print(f"result:{result}")

result = lengthOfLongestSubstring('a')
print(f"result:{result}")

result = lengthOfLongestSubstring(' ')
print(f"result:{result}")